package com.yunnuo.system.controller;

import com.yunnuo.common.controller.BaseController;
import com.yunnuo.common.domain.Tree;
import com.yunnuo.system.domain.Menu;
import com.yunnuo.system.domain.User;
import com.yunnuo.system.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @api {title} 系统首页comtroller
 * @apiName IndexController
 * @apiGroup System-IndexController
 * @apiDescription Created by 魏洪福(15064000912@163.com) on  2018/5/25.
 */
@Controller
public class IndexController extends BaseController {

    @Autowired
    private IMenuService menuService;

    /**
     * @api {get} /index  跳转系统登陆
     * @apiName index
     * @apiGroup System-IndexController
     */
    @GetMapping("/index")
    String index(Model model) {
        List<Tree<Menu>> menus = menuService.listMenuTree(getUserId());
        model.addAttribute("menus", menus);
        model.addAttribute("name", getUser().getRealName());
        model.addAttribute("username", getUser().getLoginName());
        return "index";
    }

    /**
     * @api {get} /main  跳转系统main页面
     * @apiName main
     * @apiGroup System-IndexController
     */
    @GetMapping("/main")
    String main() {
        return "main";
    }

}
